package com.yanmaohu.nikita.utility;

/**
 * @author Bright Lee
 */
public final class TimeUtility {

    public static String useTime(long beginTimes) {
        long ts = System.currentTimeMillis() - beginTimes;
        if (ts < 1000) {
            return ts + " milliseconds";
        }
        long hours = ts / (60 * 60 * 1000);
        ts = ts - hours * (60 * 60 * 1000);
        long minutes = ts / (60 * 1000);
        ts = ts - minutes * (60 * 1000);
        long seconds = ts / 1000;
        ts = ts - seconds * 1000;
        if (ts >= 500) {
            seconds++;
        }
        String useTime = "";
        if (hours > 0) {
            if (hours == 1) {
                useTime += hours + " hour";
            } else {
                useTime += hours + " hours";
            }
        }
        if (minutes > 0) {
            if (!useTime.isEmpty()) {
                useTime += ", ";
            }
            if (minutes == 1) {
                useTime += minutes + " minute";
            } else {
                useTime += minutes + " minutes";
            }
        }
        if (seconds >= 0) {
            if (!useTime.isEmpty()) {
                useTime += ", ";
            }
            if (seconds == 1) {
                useTime += seconds + " second";
            } else {
                useTime += seconds + " seconds";
            }
        }
        return useTime;
    }

}
